<template>
  <view>
    <nav-bar title="专家团队"></nav-bar>
      <you-scroll
      :loadingHeight="loadingHeight"
      :mainHeight="scrollHeight"
      :isAllData="isAllData"
      :isRequestSuccess="isRequestSuccess"
      @onRefresh="onRefresh"
      @loadMore="loadMore"
    >
      <template>
        <view v-if="isLoading" class="common-loading">
          <image class="loading-img" :src="baseIconUrl + '/commonIcon/icon_loading.png'" />
          正在加载数据，请稍后......
        </view>
        <view class="common-no-data" v-else-if="!expertTeamList || expertTeamList.length === 0">
          <image class="no-data-img" :src="baseIconUrl + '/commonIcon/icon_no_data.png'" />
          <view class="text">暂无数据</view>
        </view>
        <view v-else>
          <expertTeam-list :expertTeamList="expertTeamList"></expertTeam-list>
        </view>
      </template>
    </you-scroll>
  </view>
</template>

<script>
  import ExpertTeamList from '../../components/expertTeamList.vue'
  import api_professor from '@/api/user.js'
  import { baseUrl, baseIconUrl } from '@/config'
  export default {
    name: 'ExpertTeamList',
    components: { ExpertTeamList },
    data() {
      return {
        baseUrl,
        baseIconUrl,
        loadingHeight: '',
        scrollHeight: '',
        isAllData: false,
        isRequestSuccess: false,
        isLoading: false,
        pageNum: 1,
        pageSize: 10,
        total: 0,
        expertTeamList: []
      }
    },
    onLoad() {
      this.scrollHeight = this.$store.getters.heightData.noTabMainHeight + 'px'
      this.loadingHeight = this.$store.getters.heightData.noTabMainHeight - 20 + 'px'
      this.getExpertTeamList()
    },
    methods: {
      getExpertTeamList() {
        const params = {
          pageNum: this.pageNum,
          pageSize: this.pageSize
        }
        api_professor.professorList(params).then(res => {
          const result = res.rows
          result.forEach(item => {
            if (!item.proPhoto) return
            item.proPhoto = item.proPhoto.includes('http') ? item.proPhoto : this.baseUrl + item.proPhoto
          })
          this.expertTeamList.push(...res.rows)
          this.total = res.total
          this.isRequestSuccess = true
          this.isLoading = false
      })
      },
      // 下拉刷新
      onRefresh() {
        this.pageNum = 1
        this.expertTeamList = []
        this.isAllData = false
        this.isRequestSuccess = false
        this.getExpertTeamList()
      },
      // 上拉加载
      loadMore() {
        if (this.expertTeamList.length < this.total) {
          this.pageNum++
          this.isAllData = false
          this.isRequestSuccess = false
          this.getExpertTeamList()
        } else {
          this.isAllData = true
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
</style>
